package com.wpw.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import org.springframework.core.annotation.Order;

	
/**
 * 比较核心的代码是自定义类上面加上@WebFilter，其中@Order注解表示执行过滤顺序，值越小，越先执行
 * 在spring-boot的入口处加上如下注解@ServletComponentScan：
 * 
 * Project Name：springboot-demo
 * ClassName：NewMyFilter
 * Description：
 * @author: wupengwei
 * @date: 2017年12月28日 下午4:09:45
 * note:
 *
 */
@Order(2)
//TODO WebConfiguration加入了另一个filter，设置的顺序比该值大，但是该filter并没有在那个filter前执行
@WebFilter(filterName = "newMyFilter", urlPatterns = "/*")
public class NewMyFilter implements Filter {
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
			throws IOException, ServletException {
		System.out.println("newMyFilter");
		filterChain.doFilter(servletRequest, servletResponse);
	}

	@Override
	public void destroy() {

	}
}
